<?php
require('clases/variable.class.php');
$objVariables = new Variables;
$consulta = $objVariables->mostrar_variables();
?>
<script type="text/javascript">
    $(document).ready(function(){
        // mostrar formulario de actualizar datos
        $("table tr .modi a").click(function(){
            $('#tabla').hide();
            $("#formulario").show();
            $.ajax({
                url: this.href,
                type: "GET",
                success: function(datos){
                    $("#formulario").html(datos);
                }
            });
            return false;
        });
	
        // llamar a formulario nuevo
        $("#nuevo a").click(function(){
            $("#formulario").show();
            $("#tabla").hide();
            $.ajax({
                type: "GET",
                url: 'nvariable.php',
                success: function(datos){
                    $("#formulario").html(datos);
                }
            });
            return false;
        });
    });

</script>
<div id="container">

    <div id="demo">

        <span id="nuevo"><a href="nvariable.php"><img src="img/add.png" alt="Agregar dato" /></a></span><br/><br/>
        <table id="example" class="display">
            <thead>
                <tr>
                    <th>Variable</th>    		
                    <th>Valor</th>    		
                    <th>Fecha de Creaci&oacute;n</th>            
                    <th>Editar</th>
                    <th>Eliminar</th>
                </tr>
            </thead>
            <tbody>
                <?php
                if ($consulta) {
                    while ($variable = mysql_fetch_array($consulta)) {
                        ?>

                        <tr id="fila-<?php echo $variable['id'] ?>">
                            <td><?php echo $variable['var'] ?></td>
                            <td><?php echo $variable['valor'] ?></td>
                            <td><?php echo $variable['fecha'] ?></td>
                            <td class="center"><span class="modi"><a href="actvariable.php?id=<?php echo $variable['id'] ?>"><img src="img/database_edit.png" title="Editar" alt="Editar" /></a></span></td>
                            <td class="center"><span class="dele"><a onClick="EliminarVariable(<?php echo $variable['id'] ?>); return false;" href="sprvariable.php?id=<?php echo $variable['id'] ?>"><img src="img/delete.png" title="Eliminar" alt="Eliminar" /></a></span></td>
                        </tr>
                        <?php
                    }
                }
                ?></tbody>
        </table>
    </div>
    <div class="spacer"></div>
</div>